/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.logiclander.whozwho.data.dao;

import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Date;
import com.google.common.base.Objects;

/**
 *
 * @author logiclander
 */
public class SystemDto {
  private final Long sid;
  private final String title;
  private final Date expired;

	public static final SystemDto EMPTY_SYSTEM_DTO =
			emptySystemDto();

	public static class Builder {

		private Long sid = Long.valueOf(0l);
		private String title = "";
		private Date expired = null;

		public Builder sid(Long sid) {
			this.sid = checkNotNull(sid,
					"Required synthetic ID cannot be null.");
			return this;
		}

		public Builder title(String title) {
			this.title = checkNotNull(title,
					"Required title cannot be null.");
			return this;
		}

		public Builder expired(Date expired) {
			checkNotNull(expired, "Required expire date cannot be null.");
			this.expired = new Date(expired.getTime());
			return this;
		}

		public SystemDto build() {
			return new SystemDto(this);
		}
	}

	private SystemDto(Builder builder) {
		this.sid = builder.sid;
		this.title = builder.title;

		if (builder.expired != null) {
			this.expired = new Date(builder.expired.getTime());
		} else {
			this.expired = null;
		}
	}

	public static SystemDto.Builder builder() {
		return new Builder();
	}

	public static SystemDto.Builder mutableCopyOf(
			SystemDto sd) {
		SystemDto.Builder copy = new Builder();

		copy.sid(sd.getSid())
			.title(sd.getTitle())
			.expired(sd.getExpired());

		return copy;
	}

	public static SystemDto emptySystemDto() {
		return builder().build();
	}

	public Long getSid() {
		return sid;
	}

	public String getTitle() {
		return title;
	}

	public Date getExpired() {
		Date expiredCopy = null;
		if (expired != null) {
			expiredCopy = new Date(expired.getTime());
		}

		return expiredCopy;
	}

	@Override
	public String toString() {
		return Objects.toStringHelper(this)
				.add("sid", sid)
				.add("title", title)
				.add("expired", expired)
				.toString();
	}

	@Override
	public int hashCode() {
		return Objects.hashCode(sid, title, expired);
	}

	@Override
	public boolean equals(Object obj) {

		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SystemDto other = (SystemDto) obj;

		return Objects.equal(sid, other.getSid()) &&
				Objects.equal(title, other.getTitle()) &&
				Objects.equal(expired, other.getExpired());
	}

}
